//
//  NProblemTableViewTitleViewCell.m
//  nncloud
//
//  Created by gdy on 2018/9/26.
//  Copyright © 2018年 youedata. All rights reserved.
//

#import "NProblemTableViewTitleViewCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "NSDate+Extension.h"

@interface NProblemTableViewTitleViewCell()

@property(nonatomic, strong) UILabel *titleLb;
@property(nonatomic, strong) UILabel *rightLb;

@property(nonatomic, strong) UILabel *rightTLb;

@property(nonatomic, strong) UIImageView *line;
@property(nonatomic, strong) UIImageView *iconImageV;
@property(nonatomic, strong) UILabel *nameLb;
@property(nonatomic, strong) UILabel *timeLb;

@end

//-----------------color-----------

#define cTitleColor   0x949596
//#define cNameColor   0x535455
//#define cTimeColor   0xa2a3a4

@implementation NProblemTableViewTitleViewCell


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = 0;
        //1
        self.titleLb = [UILabel new];
        self.titleLb.font = [UIFont systemFontOfSize:15];
        self.titleLb.numberOfLines = 0;
        self.titleLb.textColor = NColorFrom16RGB(cTitleColor);
        [self addSubview:self.titleLb];
        [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(@10);
            make.right.equalTo(self.contentView.mas_right).offset(-10);
            make.top.mas_equalTo(@2);
//            make.size.mas_equalTo(CGSizeMake(345, 30));
            make.height.equalTo(@38);
        }];
        
        self.rightTLb = [UILabel new];
        self.rightTLb.font = [UIFont systemFontOfSize:14];
        [self.rightTLb setBackgroundColor:[UIColor whiteColor]];
        self.rightTLb.textColor = NColorFrom16RGB(0x76abf8);
        self.rightTLb.layer.cornerRadius = 5;
        self.rightTLb.layer.borderWidth = 1;
        self.rightTLb.layer.borderColor = NColorFrom16RGB(0x76abf8).CGColor;
        self.rightTLb.layer.masksToBounds = YES;
        [self.contentView addSubview:self.rightTLb];
        [self.rightTLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(@-10);
            make.top.mas_equalTo(39);
            make.height.mas_equalTo(@20);
//            make.centerY.equalTo(self.titleLb);
            //            make.size.width.mas_equalTo(@30);
        }];

//        //2   76abf8
        self.rightLb = [UILabel new];
        self.rightLb.font = [UIFont systemFontOfSize:14];
        [self.rightLb setBackgroundColor:[UIColor whiteColor]];
        self.rightLb.textColor = NColorFrom16RGB(0x76abf8);
        self.rightLb.layer.cornerRadius = 5;
        self.rightLb.layer.borderWidth = 1;
        self.rightLb.layer.borderColor = NColorFrom16RGB(0x76abf8).CGColor;
        self.rightLb.layer.masksToBounds = YES;
        [self.contentView addSubview:self.rightLb];
        [self.rightLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.rightTLb.mas_left).mas_offset(@-10);
//            make.top.mas_equalTo(35);
            make.height.mas_equalTo(@20);
            make.centerY.equalTo(self.rightTLb);
//            make.size.width.mas_equalTo(@30);
        }];
//
//        //3
        self.line = [UIImageView new];
        [self.contentView addSubview:self.line];
        self.line.backgroundColor = [UIColor clearColor];
        [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(@0);
            make.top.equalTo(self.titleLb.mas_bottom).mas_offset(@15);
            make.height.mas_equalTo(@5);
        }];
//        //4
        self.iconImageV = [UIImageView new];
        self.iconImageV.layer.cornerRadius = 25.f;
        self.iconImageV.layer.masksToBounds = YES;
        [self.contentView addSubview:self.iconImageV];
        [self.iconImageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLb);
            make.top.equalTo(self.line.mas_bottom).mas_offset(@20);
            make.size.mas_equalTo(CGSizeMake(50, 50));
        }];
//
//        //5
        self.nameLb = [UILabel new];
        self.nameLb.textColor = NColorFrom16RGB(cNameColor);
        self.nameLb.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.nameLb];
        [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconImageV.mas_right).mas_offset(@5);
            make.top.equalTo(self.iconImageV);
            make.height.mas_equalTo(@25);
        }];
//
//
//        //7
        self.timeLb = [UILabel new];
        self.timeLb.textColor = NColorFrom16RGB(cTimeColor);
        self.timeLb.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:self.timeLb];
        [self.timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.height.equalTo(self.nameLb);
            make.top.equalTo(self.nameLb.mas_bottom);
//            make.height.equalTo(self.nameLb.mas_height);
            make.right.mas_equalTo(@0);
        }];
    }
    return self;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
//- (void)setCellFrame:(NProblemCellFrame *)cellFrame
//{
//    _cellFrame = cellFrame;
//
//
//}
-(void)drawRect:(CGRect)rect{
    CGPoint start=CGPointMake(0, 65);
    CGPoint end=CGPointMake(rect.size.width, 65);
    [self drawLine:[UIColor grayColor] startPoint:start endPoint:end isDash:YES];
}
/**
 绘制线图
 
 @param color 线图颜色
 @param start 开始Point
 @param end 结束Point
 @param dash 是否是虚线
 */
-(void)drawLine:(UIColor*)color startPoint:(CGPoint)start endPoint:(CGPoint)end isDash:(BOOL)dash{
    CGContextRef ctx=UIGraphicsGetCurrentContext();
    //设置颜色
    CGContextSetStrokeColorWithColor(ctx, color.CGColor);
    //设置线宽为1
    CGContextSetLineWidth(ctx, 1.0);
    if (dash) {
        CGFloat lengths[]={4,4};
        CGContextSetLineDash(ctx, 0, lengths, 2);
    }else{
        CGContextSetLineDash(ctx, 0, 0, 0);
    }
    CGContextMoveToPoint(ctx, start.x, start.y);
    CGContextAddLineToPoint(ctx, end.x, end.y);
    CGContextStrokePath(ctx);
}
- (void)setModel:(NProblemModel *)model
{
    _model= model;
    self.titleLb.text = model.questionTitle;
    self.rightTLb.text = [NSString stringWithFormat:@" %@ ",[self getStrWithType:model.questionType]];
    self.rightLb.text = [NSString stringWithFormat:@" %@ ",model.questionOfficeName];
    [self.iconImageV sd_setImageWithURL:[NSURL URLWithString:model.questionUserUrl] placeholderImage:[UIImage imageNamed:@"kefu"]];
    self.nameLb.text = model.questionUserName;
    self.timeLb.text = [NSDate timeTransfer:model.questionCreateTime];
}
- (NSString *)getStrWithType:(NSString *)type
{
    switch ([type integerValue]) {
        case 1:
            return @"咨询";
            break;
        case 2:
            return @"投诉";
            break;
        case 3:
            return @"建议";
            break;
            
        default:
            return @"咨询";
            break;
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
